package org.fly.service.impl;

import org.fly.bean.Brand;
import org.fly.bean.query.BrandQuery;
import org.fly.dao.BrandDao;
import org.fly.service.BrandService;
import org.fly.utils.UUIDFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.fly.bean.common.BusinessException;
import java.util.List;

/**
* Created by autoCode on 2018-05-02 14:52:23.
*/
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    BrandDao brandDao;

    @Override
    public List<Brand> list(BrandQuery query) {
        return brandDao.list(query);
    }

    @Override
    public long count(BrandQuery query) {
        return brandDao.count(query);
    }

    @Override
    public Brand findById(String id) {
        return brandDao.findById(id);
    }

    @Override
    public void save(Brand bean)  throws BusinessException {

    if(StringUtils.isNotBlank(bean.getId())){
         brandDao.update(bean);
    }else {
        bean.setId(UUIDFactory.random());
        bean.setCreateTime(System.currentTimeMillis());
        brandDao.insert(bean);
    }
    }

    @Override
    public void delete(String id) {
        brandDao.delete(id);
    }
}
